package springboot.doMain;

import java.io.Serializable;
import java.util.Date;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * wx_group_chat_admin
 * blueGrey
 */
@Data
@NoArgsConstructor
public class WxGroupChatAdmin implements Serializable {
	/**
	 * group_chat_seller_id
	 */
	private Long groupChatSellerId;
	
	/**
	 * 群主id
	 */
	private String owner;
	
	/**
	 * 截至当天有发过消息的客户群数量
	 */
	private Long chatHasMsg;
	
	/**
	 * 截至当天有发过消息的群成员数
	 */
	private Long memberHasMsg;
	
	/**
	 * 截至当天客户群总数量
	 */
	private Long chatTotal;
	
	/**
	 * 客户群新增群人数
	 */
	private Long newMemberCnt;
	
	/**
	 * 截至当天客户群消息总数
	 */
	private Long msgTotal;
	
	/**
	 * 截至当天客户群总人数
	 */
	private Long memberTotal;
	
	/**
	 * 新增客户群数量
	 */
	private Long newChatCnt;
	
	/**
	 * 时间
	 */
	private Date date;
	/*
	 * 时间戳
	 * */
	private Long timeStamp;
	
	private static final long serialVersionUID = 1L;
	
	public WxGroupChatAdmin(String s) {
		if (s == null ) {
			return;
		}
		JSONArray objects = JSONArray.parseArray(s);
		JSONObject jsonObjectData = objects.getJSONObject(0);
		JSONObject jsonObject = jsonObjectData.getJSONObject("data");
		this.chatHasMsg = jsonObject.getLong("chat_has_msg");
		this.memberHasMsg = jsonObject.getLong("member_has_msg");
		this.chatTotal = jsonObject.getLong("chat_total");
		this.newMemberCnt = jsonObject.getLong("new_member_cnt");
		this.msgTotal = jsonObject.getLong("msg_total");
		this.memberTotal = jsonObject.getLong("member_total");
		this.newChatCnt = jsonObject.getLong("new_chat_cnt");
		this.timeStamp = jsonObjectData.getLong("stat_time");
		this.date = new Date(this.timeStamp * 1000);
	}
	
	public static WxGroupChatAdmin getInstance(Object o) {
		if (o == null) {
			return null;
		}
		WxGroupChatAdmin wxGroupChatAdmin = new WxGroupChatAdmin();
		
		JSONObject allJsonObject = JSONObject.parseObject(o + "");
		wxGroupChatAdmin.setOwner(allJsonObject.getString("owner"));
		if (wxGroupChatAdmin.getOwner() == null) {
			return null;
		}
		JSONObject jsonObject = JSONObject.parseObject(allJsonObject.getString("data"));
		wxGroupChatAdmin.setChatTotal(jsonObject.getLong("chat_total"));
		if (wxGroupChatAdmin.getChatTotal() == 0) {
			return null;
		}
		wxGroupChatAdmin.setChatHasMsg(jsonObject.getLong("chat_has_msg"));
		wxGroupChatAdmin.setNewChatCnt(jsonObject.getLong("new_chat_cnt"));
		wxGroupChatAdmin.setNewMemberCnt(jsonObject.getLong("new_member_cnt"));
		wxGroupChatAdmin.setMemberHasMsg(jsonObject.getLong("member_has_msg"));
		wxGroupChatAdmin.setMsgTotal(jsonObject.getLong("msg_total"));
		wxGroupChatAdmin.setMemberTotal(jsonObject.getLong("member_total"));
		return wxGroupChatAdmin;
	}
}